home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + DIC_M.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
- #ifndef DICTIONARY_H
- #define DICTIONARY_H
-
- #include <LEDA/rb_tree.h>
-
- typedef rb_tree_item dic_item;
-
- #define dictionary(keytype,infotype) name3(keytype,infotype,dictionary)
-
- #define dictionarydeclare2(keytype,infotype)\
- \
- class dictionary(keytype,infotype) : public rb_tree {\
- \
- int cmp(ent& x, ent& y) const { return compare((keytype&)x,(keytype&)y); }\
- void clear_key(ent& x) const { Clear((keytype&)x); }\
- void clear_inf(ent& x) const { Clear((infotype&)x); }\
- void copy_key(ent& x) const { Copy((keytype&)x); }\
- void copy_inf(ent& x) const { Copy((infotype&)x); }\
- \
- public:\
- \
- virtual int defined(keytype y) const { return rb_tree::member(Ent(y)); }\
- virtual dic_item lookup(keytype y) const { return rb_tree::lookup(Ent(y)); }\
- virtual void change_inf(dic_item it, infotype i)\
- { rb_tree::change_inf(it,Ent(i)); }\
- \
- virtual dic_item insert(keytype y,infotype x)\
- { return rb_tree::insert(Ent(y),Ent(x)); } \
- \
- virtual void del(keytype y) { rb_tree::del(Ent(y)); } \
- virtual void del_item(dic_item it) { rb_tree::del_item(it); } \
- virtual keytype key(dic_item it) const { return keytype(rb_tree::key(it)); }\
- virtual infotype inf(dic_item it) const { return infotype(rb_tree::inf(it));}\
- infotype access(keytype k) const { return inf(lookup(k));}\
- \
- virtual bool empty() const { return rb_tree::empty(); }\
- virtual int size() const { return rb_tree::size(); }\
- virtual dic_item first_item() const { return rb_tree::first_item(); }\
- virtual dic_item next_item(dic_item it) const { return rb_tree::next_item(it); }\
- \
- virtual dictionary(keytype,infotype)& operator=(const dictionary(keytype,infotype)& D)\
- { return (dictionary(keytype,infotype)&)rb_tree::operator=((rb_tree&) D); }\
- \
- dictionary(keytype,infotype)() {}\
- dictionary(keytype,infotype)(const dictionary(keytype,infotype)& D) :\
- rb_tree((rb_tree&) D) {}\
- ~dictionary(keytype,infotype)() { rb_tree::clear(); }\
- } ;
-
-
-
- #define ITEM(T) name2(T,_item)
-
- #define DICTIONARY(ktype,itype,impl) name4(itype,ktype,impl,dictionary)
-
-
- #define DICTIONARYdeclare3(keytype,infotype,impl)\
- \
- class DICTIONARY(keytype,infotype,impl) : public dictionary(keytype,infotype),\
- public impl {\
- int cmp(ent& x, ent& y) const { return compare((keytype&)x,(keytype&)y); }\
- void clear_key(ent& x) const { Clear((keytype&)x); }\
- void clear_inf(ent& x) const { Clear((infotype&)x); }\
- void copy_key(ent& x) const { Copy((keytype&)x); }\
- void copy_inf(ent& x) const { Copy((infotype&)x); }\
- \
- public:\
- \
- int defined(keytype y) const { return impl::member(Ent(y)); }\
- dic_item lookup(keytype y) const { return dic_item(impl::lookup(Ent(y))); }\
- void change_inf(dic_item it, infotype i)\
- { impl::change_inf(ITEM(impl)(it),Ent(i));}\
- \
- dic_item insert(keytype y,infotype x)\
- { return dic_item(impl::insert(Ent(y),Ent(x))); } \
- \
- void del(keytype y) { impl::del(Ent(y)); } \
- void del_item(dic_item it) { impl::del_item(ITEM(impl)(it)); } \
- keytype key(dic_item it) const { return keytype(impl::key(ITEM(impl)(it))); }\
- infotype inf(dic_item it) const { return infotype(impl::inf(ITEM(impl)(it)));}\
- \
- bool empty() const { return impl::empty(); }\
- int size() const { return impl::size(); }\
- dic_item first_item() const { return dic_item(impl::first_item()); }\
- dic_item next_item(dic_item it) const { return dic_item(impl::next_item(ITEM(impl)(it))); }\
- \
- dictionary(keytype,infotype)& operator =(const dictionary(keytype,infotype)& D)\
- { return (DICTIONARY(keytype,infotype,impl)&)impl::operator=((impl&) D); }\
- \
- DICTIONARY(keytype,infotype,impl)() {}\
- DICTIONARY(keytype,infotype,impl)(const DICTIONARY(keytype,infotype,impl)& D) :\
- impl((impl&) D) {}\
- ~DICTIONARY(keytype,infotype,impl)() { impl::clear(); }\
- } ;
-
- // ----------------------------------------------------------------
- // iteration
- // ----------------------------------------------------------------
-
- #define forall_dic_items(i,D) for(i = (D).first_item(); i; i=(D).next_item(i))
-
- #endif
-